<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>工单</title>
    <link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
	<style type="text/css">
    	.detail{
    		padding-right: 20px!important;
    	}
    	h5,label{color: #0062CC;}
    	label{font-size: 14px;}
    	.mui-navigate-right .mui-col-xs-8{
		    width: 62.666667%!important;
    	}
    	.mui-text-right input,.mui-text-right textarea{
    		border: 0;
    		font-size: 14px;
		    font-weight: 400;
		    color: #8f8f94;
    		margin-bottom: 0;
    		text-align: right;
    	}
    </style>
</head>

<body>
    <div class="mui-content">
		<ul class="mui-table-view mui-table-view-chevron type_list_spair">
			<li class="mui-table-view-cell detail" tapmode onclick="openSaveWin('work_order_sel_tast','选择任务',{wonum: api.pageParam.wonum})">
				<div class="mui-table mui-navigate-right">
	                <div class="mui-table-cell mui-col-xs-4">
	                    <h5 class="mui-ellipsis">任务：</h5>
	                </div>
	                <div class="mui-table-cell mui-col-xs-8 mui-text-right">
	                    <span class="mui-h5" id="tastnum">请选择任务</span>
	                </div>
	           </div>
			</li>
			<li class="mui-table-view-cell detail" tapmode onclick="openSaveWin('work_order_sel_server','选择服务')">
				<div class="mui-table mui-navigate-right">
	                <div class="mui-table-cell mui-col-xs-4">
	                    <h5 class="mui-ellipsis">服务：</h5>
	                </div>
	                <div class="mui-table-cell mui-col-xs-8 mui-text-right">
	                    <span class="mui-h5" id="server">请选择服务</span>
	                </div>
	            </div>
			</li>
			<li class="mui-table-view-cell detail">
				<div class="mui-table">
	                <div class="mui-table-cell mui-col-xs-4">
	                    <h5 class="mui-ellipsis">描述：</h5>
	                </div>
	                <div class="mui-table-cell mui-col-xs-8 mui-text-right">
	                    <span class="mui-h5" id="serverdesc"></span>
	                </div>
	            </div>
			</li>
			<li class="mui-table-view-cell detail">
				<div class="mui-table">
	                <div class="mui-table-cell mui-col-xs-4">
	                    <h5 class="mui-ellipsis">数量：</h5>
	                </div>
	                <div class="mui-table-cell mui-col-xs-8 mui-text-right">
	                   <input type="number" onchange="linecost()" placeholder="请输入数量" name="" id="itemqty" value="" />
	                </div>
	            </div>
			</li>
			<li class="mui-table-view-cell detail">
				<div class="mui-table">
	                <div class="mui-table-cell mui-col-xs-4">
	                    <h5 class="mui-ellipsis">单位成本：</h5>
	                </div>
	                <div class="mui-table-cell mui-col-xs-8 mui-text-right">
	                   <input type="number" onchange="linecost()" placeholder="请输入单位成本" name="" id="unitcost" value="" />
	                </div>
	            </div>
			</li>
			<li class="mui-table-view-cell detail">
				<div class="mui-table">
	                <div class="mui-table-cell mui-col-xs-4">
	                    <h5 class="mui-ellipsis">行成本：</h5>
	                </div>
	                <div class="mui-table-cell mui-col-xs-8 mui-text-right">
	                   <span class="mui-h5" id="lineText">0.00</span>
	                </div>
	            </div>
			</li>
		</ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script src="../script/mui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../script/common.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    var UILoading, UIloadId;
    var itemqty = '',
    	wonum = '',
        unitcost = '',
        linecost = '',
        taskduration = '';
        itemnum = '';
    apiready = function() {
        UILoading = api.require('UILoading');
        api.addEventListener({
            name: 'TastId'
        }, function(ret, err) {
            wonum = ret.value.tastnum;
            $api.html($api.byId('tastnum'), ret.value.description)
        });
        api.addEventListener({
            name: 'server'
        }, function(ret, err) {
            itemnum = ret.value.itemnum;
            $api.html($api.byId('server'), ret.value.itemnum)
            $api.html($api.byId('serverdesc'), ret.value.description)
        });
        api.addEventListener({
            name: 'navitembtn'
        }, function(ret, err) {
            if (ret.index == 0) {
                if ($api.html($api.byId('tastnum')) == '请选择任务') {
                    Toast('请选择任务！');
                    return
                }
                if ($api.html($api.byId('server')) == '请选择服务') {
                    Toast('请选择服务！');
                    return
                }
                if ($api.val($api.byId('itemqty')) == '') {
                    Toast('请填写数量！');
                    return
                }
                if ($api.val($api.byId('unitcost')) == '') {
                    Toast('请填写单位成本！');
                    return
                }
                UILoading.flower({}, function(ret) {
                    UIloadId = ret.id;
                });
                ajaxrd("savePlanService", {
                	wonum: wonum,
                    itemqty: $api.val($api.byId('itemqty')),
                    unitcost: $api.val($api.byId('unitcost')),
			        linecost: $api.text($api.byId('lineText')),
			        itemnum: itemnum
                }, function(ret, err) {
                    UILoading.closeFlower({
                        id: UIloadId
                    });
                    api.sendEvent({
                        name: 'refersh',
                        extra: {
                            isrefersh: 'yes'
                        }
                    });
                    Toast('新增成功！');
                    setTimeout(function() {
                        api.closeWin();
                    }, 500)
                })
            } else { //扫码

            }
        });
    }
	var linecost = function () {
		if ($api.val($api.byId('itemqty')) =='' || $api.val($api.byId('unitcost')) == '') {
			return
		}
		$api.text($api.byId('lineText'),$api.val($api.byId('itemqty')) * $api.val($api.byId('unitcost')))
	}
</script>

</html>
